<!DOCTYPE html>
<html>
<head>
    <!-- 页面meta -->
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>传智健康</title>
    <meta name="description" content="传智健康">
    <meta name="keywords" content="传智健康">
    <meta content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no" name="viewport">
    <!-- 引入样式 -->
    <link rel="stylesheet" href="../plugins/elementui/index.css">
    <link rel="stylesheet" href="../plugins/font-awesome/css/font-awesome.min.css">
    <link rel="stylesheet" href="../css/style.css">
</head>
<body class="hold-transition">
<div id="app">
    <div class="content-header">
        <h1>密码管理
            <small>修改密码</small>
        </h1>
        <el-breadcrumb separator-class="el-icon-arrow-right" class="breadcrumb">
            <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
            <el-breadcrumb-item>密码管理</el-breadcrumb-item>
            <el-breadcrumb-item>修改密码</el-breadcrumb-item>
        </el-breadcrumb>
    </div>
    <div class="app-container">
        <template>
            <div class="app-container common-list-page">
                <el-form
                        :model="resetForm"
                        :rules="rules"
                        ref="resetForm"
                        status-icon
                        label-width="100px"
                >
                    <el-form-item label="原密码：" prop="oldPassword" :error="errorMsg_old">
                        <el-input type="password" v-model="resetForm.oldPassword" auto-complete="off"
                                  placeholder="请输入原密码"
                                  prefix-icon="el-icon-edit"></el-input>
                    </el-form-item>
                    <el-form-item label="新密码：" prop="newPasswordOne" :error="errorMsg_newOne">
                        <el-input type="password" v-model="resetForm.newPasswordOne" auto-complete="off"
                                  placeholder="请输入新密码(密码长度为3-8位)"
                                  prefix-icon="el-icon-edit"></el-input>
                    </el-form-item>
                    <el-form-item label="确认密码：" prop="newPasswordTwo" :error="errorMsg_newTwo">
                        <el-input type="password" v-model="resetForm.newPasswordTwo" auto-complete="off"
                                  placeholder="请输入确认密码(密码长度为3-8位)"
                                  prefix-icon="el-icon-edit"></el-input>
                    </el-form-item>
                    <el-form-item>
                        <el-button type="primary" @click="password()">确认修改</el-button>
                        <el-button><a href="../index1.html">取消修改</a></el-button>
                    </el-form-item>
                </el-form>
            </div>
        </template>
    </div>
</div>
</body>
<!-- 引入组件库 -->
<script src="../js/vue.js"></script>
<script src="../plugins/elementui/index.js"></script>
<script type="text/javascript" src="../js/jquery.min.js"></script>
<script src="../js/axios-0.18.0.js"></script>
<script>
    var vue = new Vue({
        el: '#app',
        data() {
            var validatePass = (rule, value, callback) => {
                if (!value) {
                    callback(new Error("请输入新密码"));
                } else if (value.toString().length < 3 || value.toString().length > 8) {
                    callback(new Error("密码长度为3-8位"));
                } else if (value === this.resetForm.oldPassword) {
                    callback(new Error("密码未做任何修改"));
                } else {
                    callback();
                }
            };
            var validatePass2 = (rule, value, callback) => {
                if (value === "") {
                    callback(new Error("请再次输入密码"));
                } else if (value !== this.resetForm.newPasswordOne) {
                    callback(new Error("两次输入密码不一致!"));
                } else {
                    callback();
                }
            };
            return {
                resetForm: {},
                errorMsg_old: null,
                errorMsg_newOne: null,
                errorMsg_newTwo: null,
                rules: {
                    oldPassword: [
                        {required: true, message: "请输入旧密码", trigger: 'blur'}
                    ],
                    newPasswordOne: [
                        {required: true, validator: validatePass, trigger: 'blur'}
                    ],
                    newPasswordTwo: [
                        {required: true, validator: validatePass2, trigger: "blur"}
                    ]
                }
            };
        },
        methods: {
            password() {
                this.errorMsg_old = null;
                this.errorMsg_newOne = null;
                this.errorMsg_newTwo = null;
                this.$refs['resetForm'].validate((valid) => {
                    if (valid) {
                        axios.post("/user/passwordUser.do", this.resetForm).then(
                            res => {
                                if (res.data.data == null) {
                                    this.$message({
                                        message: res.data.message,
                                        type: res.data.flag ? 'success' : 'error'
                                    });
                                    setTimeout(function () {
                                        location.href = "../index1.html";
                                    },1000);
                                } else {
                                    if (res.data.data == 1) {
                                        this.errorMsg_old = res.data.message;
                                    } else if (res.data.data == 2) {
                                        this.errorMsg_newOne = res.data.message;
                                    } else if (res.data.data == 3) {
                                        this.errorMsg_newTwo = res.data.message;
                                    }
                                }
                            }
                        );
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            }
        }
    })
</script>
</html>